package com.sanjishu.enterlab.electricity.sale.controller;

import com.sanjishu.enterlab.electricity.sale.domain.City;
import com.sanjishu.enterlab.electricity.sale.service.CityService;
import com.sanjishu.enterlab.electricity.sale.service.FileService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

@Controller
@RequestMapping("common")
public class CommonController {

    private static final Logger log = LoggerFactory.getLogger(CommonController.class);

    @Autowired
    private FileService fileService;
    @Autowired
    private CityService cityService;

    @RequestMapping(value="uploadImg",method= RequestMethod.POST)
    @ResponseBody
    public Response uploadImg(MultipartFile file){
        log.info("上传图片");
        return fileService.uploadImg(file);
    }

    @RequestMapping(value="chooseArea",method= RequestMethod.POST)
    @ResponseBody
    public Response chooseArea(Integer cityId){
        List<City> areaList = cityService.getArea(cityId);
        return Response.getSuccess(areaList);
    }
}
